    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package imclient;

import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JOptionPane;

/**
 * This is the implementation class for IAdvertisement Engine. This class
 * is utilized to generate advertisements. 
 *
 * @author Andrew
 */
public class AdvertisementEngineStub implements IAdvertisementEngine {

    /**
     * this uses an array of advertisements and utilizes the Random class to
     * call a random number from 0-10 to select an advertisement from the array
     *@param null
     * @return String
     */
    public String getAdvertisement() {
        //grab grab random number from 0-9
        int i = (int) (Math.random() * 10);
        //create new XML Reader Object
        XMLReader reader = new XMLReader();
        
        //Create hashmap of the ads.xml 
        HashMap<String, String> hash;
        
        //Create hashmap of the config.xml file
        HashMap<String, String> errorHash = new HashMap<String, String>();
        
        //create string to read the error message from the hashmap
        String errorMessage = new String();
        
        //search hashmap for corresponding element
        String getAdAtIndex = "ad"+i;
        //create new String object to pass return call
        String advertisement = new String();
        
        //Try catch to read from files
        try {
            hash = reader.readXML("ads.xml");
            //returnedMessage.setContent(hash.get("dummyMessage"));
            //errorMessage = hash.get("errorMessage");
            advertisement = hash.get(getAdAtIndex.toString());
            errorHash = reader.readXML("config.xml");
            
            
            
        } catch (Exception e) {
            
            JOptionPane.showInputDialog(errorHash.get("errorMessage").toString());
            
        
        
        }

        
        //Old Method to grab advertisements
        
        /*String[] adEngine;
        adEngine = new String[10];
        adEngine[0] = "Road Kill Grill: Fast Food, Made Faster!";
        adEngine[1] = "Try BeaverWax! Keeping Your Furry Friends Clean for more Than 50 Years!";
        adEngine[2] = "Skoal Chewing Tobacco: American Grown Since 1934";
        adEngine[3] = "Need Security? Call 18002672001 and Get Alarm Force, Today!";
        adEngine[4] = "For A Good Time, Call Jenny At 867-5309";
        adEngine[5] = "Ran out of ideas? Try Idea Wiz, the one and only idea generating gizmo";
        adEngine[6] = "Orbitz! For a good, clean feeling no matter what!";
        adEngine[7] = "Unique advertisement #8...";
        adEngine[8] = "Unique advertisement #9...";
        adEngine[9] = "NOW we have 10!";
        */
        
        return advertisement;
    }
}
